package com.wf.day_0531.test2;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author mpk
 * @since 2024/5/31 17:16:27
 */

/*去除ArrayList集合中重复元素
        1>.存入字符串元素
        2>.存入自定义对象元素（如Person对象）*/
public class Demo {
    public static void main(String[] args) {


        List<Person> people = new ArrayList<>();

        Collections.addAll(people,
                new Person("John", 18),
                new Person("admin", 19),
                new Person("user", 20),
                new Person("user", 20),
                new Person("superAdmin", 32),
                new Person("zhangSan", 312));

        System.out.println("去重前：");
        people.forEach(System.out::println);

        people = people.stream()
                .distinct().collect(Collectors.toList());
        System.out.println("去重后：");
        people.forEach(System.out::println);


    }


}
